#include "UIXmlEx.h"
#include "FCDraw.h"
#include "MyChart.h"
#include "LatestDiv.h"
#include "SecurityList.h"

UIXmlEx::UIXmlEx(){
    m_scaleFactor = 1;
}

double UIXmlEx::getScaleFactor()
{
    return m_scaleFactor;
}

void UIXmlEx::setScaleFactor(double value){
    m_scaleFactor = value;
    if (getNative() != 0)
    {
        getNative()->getPaint()->setScaleFactor(m_scaleFactor, m_scaleFactor);
    }
}

FCView* UIXmlEx::createView(xmlNodePtr node, const String& type){
    int typeLen = type.length();
    switch (typeLen)
    {
        case 4:
        case 5:
            {
                if (type == L"input" || type == L"view")
                {
                    xmlAttr *attribute = node->properties;
                    while (attribute){
                        String name = FCTran::stringToString((char*)attribute->name);
                        if (name == L"type")
                        {
                            String inputType = FCTran::stringToString((char*)attribute->name);
                            if (inputType == L"button")
                            {
                                if (inputType == L"button")
                                    return new FCButton();
                                if (inputType == L"checkbox")
                                    {
                                        FCCheckBox* checkBox = new FCCheckBox ;
                                        checkBox->setButtonBackColor(USERCOLOR104);
                                        return checkBox;
                                    }
                                if (inputType == L"radio")
                                    {
                                        FCRadioButton* radioButton = new FCRadioButton; FCRadioButton();
                                        radioButton->setButtonBackColor(USERCOLOR104);
                                        return radioButton;
                                    }
                                if (inputType == L"text")
                                    return new FCTextBox();
                                if (inputType == L"usercontrol")
                                if (inputType == L"custom")
                                    return createCustomView(node);
                            }
                            break;
                        }
                    }
                }
                break;
            }
        case 7:
            if (type == L"mychart")
            {
                return new MyChart();
            }
            break;
        case 9:
            {
                if (type == L"latestdiv")
                {
                    return new LatestDiv();
                }
                break;
            }
    }
    if (typeLen > 10)
    {
        if (type == L"securitylist")
        {
            return new SecurityList();
        }
    }
    return FCUIXml::createView(node, type);
}

void UIXmlEx::resetScaleSize(FCSize clientSize){
    FCNative *native = getNative();
    if (native != 0)
    {
        FCSize size;
        size.cx = (int)(clientSize.cx * m_scaleFactor);
        size.cy = (int)(clientSize.cy * m_scaleFactor);
        native->setScaleSize(size);
        native->update();
    }
}
